//
//  MapViewController.m
//  StationManager
//
//  Created by Helong on 17/3/3.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "MapViewController.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
#import <BaiduMapAPI_Map/BMKMapComponent.h>
#import <BaiduMapAPI_Location/BMKLocationComponent.h>
#import <BaiduMapAPI_Search/BMKSearchComponent.h>
#import "STMPinAnnotationView.h" //自定义标注（带有站名和显示温度或者降雨的label）
#import "STMPointAnnotation.h"
#import "BottomView.h"
#import "DataHandel.h"
#import "StationInfoModel.h"
#import "RightTopButton.h"
#import "DetailViewController.h"
#import "TaskViewController.h"
#import "UserInfoAlertView.h"
#import "RightMoreView.h"
#import "MeInfoView.h"
#import "UserInfoModel.h"
#import "SearchViewController.h"
#import "MaintainViewController.h"
#import "UIButton+typeLayout.h"
#import "StatusModel.h"
#import "AFNwebManager.h"
@interface MapViewController ()<BMKMapViewDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate>
//地图
@property (nonatomic,strong) BMKMapView* mapView;
//定位
@property (nonatomic,strong) BMKLocationService *locService;
@property (nonatomic, strong)BMKGeoCodeSearch *geocodesearch;
//存放标注经纬度数据的数组
@property (nonatomic,strong) NSMutableArray *annotationArray;
//故障标注类对象数组
@property (nonatomic,strong) NSMutableArray *badAnnotationArray;
@property (nonatomic,strong) NSMutableArray *urgentAnnotationArray;
@property (nonatomic,strong) NSMutableArray *yunweiAnnotationArray;
//站点信息model数组
@property (nonatomic,strong) NSMutableArray *stationArray;
//故障站点数组
@property (nonatomic,strong) NSMutableArray *badStationArray;
//紧急站点数组
@property (nonatomic,strong) NSMutableArray *urgencyStationArray;
//运维站点数组
@property (nonatomic,strong) NSMutableArray *operationStationArray;
///弹出的底部视图
@property (nonatomic,strong) BottomView *bottomView;
//右上角button
@property (nonatomic,strong) RightTopButton *rightTopButton;
//降雨按钮
@property (nonatomic,strong) UIButton *jiangyuButton;
//温度按钮
@property (nonatomic,strong) UIButton *wenduButton;
///右上角更多选项视图
@property (nonatomic,strong) RightMoreView *moreView;
//用户所在纬度
@property (nonatomic,assign) CGFloat userLatitude;
//用户所在经度
@property (nonatomic,assign) CGFloat userLongitude;
//紧急站点标注视图数组
@property (nonatomic,strong) NSMutableArray *urgentAnnotationViewArray;

@property (nonatomic,strong) NSTimer *timer;

@property (nonatomic,strong) NSTimer *timer1;
//地图右下角类型按钮
@property (nonatomic,strong) UIButton *typeButton;
@property (nonatomic , copy) NSString *currentTime;
@property (nonatomic , copy) NSString *currentLocation;
@property (nonatomic , strong) NSMutableArray *statusArray;
@property (nonatomic , strong) UITextField *searchTF;

@end

@implementation MapViewController

//视图将要显示
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [_mapView viewWillAppear];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(located:) name:@"Located" object:nil];
    [[AFNwebManager shareAFNWebManager] SOAPData:nil Http:@"http://121.28.100.2:83/Phone/PhoneService.asmx" soapMethod:@"GetCurrentTime" success:^(id responseObject) {
        
        _currentTime = responseObject;
        
    } failure:^{
        
    }];
    
    
    
    if (_currentTime.length == 0) {
        
        NSDate *date = [NSDate date];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"YYYY-MM-dd HH:MM:ss"];
        //    NSString * endTIme = [formatter stringFromDate:date];
        
        _currentTime = [formatter stringFromDate:date];
       
    }
    
    //添加台站站点
}

#pragma mark Notification - Delegate

- (void)located:(NSNotification *)notify {
    [_locService stopUserLocationService];
    NSArray * pointArray = (NSArray *)notify.object;
    CGFloat latitude = [pointArray[0] floatValue];
    CGFloat longitude = [pointArray[1] floatValue];
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
    BMKCoordinateRegion region ;
    region.center = coordinate;
    region.span.latitudeDelta = 0.02;
    region.span.longitudeDelta = 0.02;
    [_mapView setRegion:region animated:YES];
    [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(8*wl);
        make.top.equalTo(self.view.mas_bottom);
        make.right.equalTo(self.view.mas_right).offset(-8*wl);
        make.height.mas_equalTo(180*hl);
    }];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_locService stopUserLocationService];//不用时，关闭定位
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil
}

//不用时移除通知
- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Located" object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //存放闪点标注数组
    _urgentAnnotationViewArray = [NSMutableArray array];
    _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    //显示比例尺
    _mapView.showMapScaleBar = YES;
    _mapView.zoomLevel = 10;
    [self.view addSubview:_mapView];
    self.title = @"台站运维监测系统";
    _currentLocation = @"";
    //添加功能按钮
    [self addFunctionalButtons];
//    添加右下角类型按钮
    [self addTypeButton];
 
    //开启定位
    [self locationOnMap];
    //添加底部视图
    [self addBottomView];
    //添加右上方的按钮
    [self addRightTopButton];
    //添加搜索按钮
    [self addSearchButton];
    ///右上角更多选择视图
    [self addRightMoreView];
    
    _statusArray = [NSMutableArray arrayWithCapacity:0];
    [[DataHandel sharedDataHandel] getStationStatusWithBlock:^(id object) {
        _statusArray = object;
//        NSLog(@"LLLLL:%@",_statusArray);
        [self addAnnotation];

    }];
}


#pragma mark -- 添加地图右下角类型按钮
-(void) addTypeButton{
    
    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = [UIColor whiteColor];
    backView.layer.masksToBounds = YES;
    backView.layer.borderWidth = 1;
    backView.layer.cornerRadius = 5;
    backView.layer.borderColor = [UIColor blackColor].CGColor;
    [self.view addSubview:backView];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-50*hl);
        make.size.mas_equalTo(CGSizeMake(90, 125));
    }];
    
    NSArray *titleArray = @[@"单要素站",@"两要素站",@"四要素站",@"六要素站",@"国土站   "];
    NSArray *imageArray = @[@"B",@"D",@"T",@"A",@"G"];
    for (int i = 0; i<titleArray.count; i++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:titleArray[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:10];
        [button setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateHighlighted];
        button.tag = 100+i;
        [button layoutButtonWithEdgeInsetsStyle:HLButtonEdgeInsetsStyleLeft imageTitleSpace:15];
        [button addTarget:self action:@selector(typeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(0, i*25, 90, 25);
        [backView addSubview:button];
    }
    
}

-(void)typeButtonClick:(UIButton *)button{
    
    
    NSLog(@"tag:%zi",button.tag);
    NSMutableArray *typeArray = [NSMutableArray arrayWithCapacity:0];
    if (button.tag == 100) {
        
        for (STMPointAnnotation *annotation in self.annotationArray) {
            if ([annotation.stationModel.stationType isEqualToString:@"T1"]) {
                [typeArray addObject:annotation];
            }
            
        }
    }
    else if (button.tag == 101){
        for (STMPointAnnotation *annotation in self.annotationArray) {
            if ([annotation.stationModel.stationType isEqualToString:@"T2"]) {
                [typeArray addObject:annotation];
            }
            
        }
    }
    else if (button.tag == 102){
        for (STMPointAnnotation *annotation in self.annotationArray) {
            if ([annotation.stationModel.stationType isEqualToString:@"T4"]) {
                [typeArray addObject:annotation];
            }
            
        }
    }
    else if (button.tag == 103){
        for (STMPointAnnotation *annotation in self.annotationArray) {
            if ([annotation.stationModel.stationType isEqualToString:@"T6"]) {
                [typeArray addObject:annotation];
            }
            
        }
    }
    else{
        for (STMPointAnnotation *annotation in self.annotationArray) {
            if ([annotation.stationModel.stationType isEqualToString:@"G2"]) {
                [typeArray addObject:annotation];
            }
                
        }

    }

    [self.mapView removeAnnotations:self.annotationArray];
    [self.mapView addAnnotations:typeArray];
}

#pragma mark -- 添加搜索按钮
- (void)addSearchButton{
//    UIButton *button = [[UIButton alloc]init];
//    [self.view addSubview:button];
//    button.backgroundColor = RGBCOLOR(255, 255, 255);
//    button.layer.masksToBounds = YES;
//    button.layer.cornerRadius = 5;
//    [button mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self.view);
//        make.top.equalTo(self.view).offset(20*hl);
//        make.size.mas_equalTo(CGSizeMake(120*wl, 30*hl));
//    }];
//    [button setTitle:@"🔍 搜索" forState:UIControlStateNormal];
//    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [button.titleLabel setFont:TEXT_FONT];
//    [button addTarget:self action:@selector(searchButtonDidSelected:) forControlEvents:UIControlEventTouchUpInside];
    
    _searchTF = [[UITextField alloc] init];
    _searchTF.borderStyle = UITextBorderStyleRoundedRect;
    _searchTF.placeholder = @"🔍 站号/站名";
    _searchTF.font = [UIFont systemFontOfSize:14];
    
    UIToolbar * tool = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    UIBarButtonItem * done = [[UIBarButtonItem alloc]initWithTitle:@"搜索" style:UIBarButtonItemStyleDone target:self action:@selector(doneClick)];
    UIBarButtonItem * space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    NSArray * array = @[space,done];
    [tool setItems:array];
    [_searchTF setInputAccessoryView:tool];
    [self.view addSubview:_searchTF];
    
    [_searchTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(20*hl);
        make.size.mas_equalTo(CGSizeMake(120*wl, 30*hl));
    }];
}

-(void)doneClick{
    
    [_searchTF resignFirstResponder];
    
    if (_searchTF.text.length == 0) {
        
        [self.mapView removeAnnotations:self.mapView.annotations];
        _statusArray = [NSMutableArray arrayWithCapacity:0];
        [[DataHandel sharedDataHandel] getStationStatusWithBlock:^(id object) {
            _statusArray = object;
            [self addAnnotation];
            
        }];
    }
    else{
        
        NSMutableArray *searchArray = [NSMutableArray arrayWithCapacity:0];
        for (STMPointAnnotation *annotation in _annotationArray) {
            
            if ([annotation.stationModel.stationNum containsString:_searchTF.text] || [annotation.stationModel.stationName containsString:_searchTF.text]) {
                
                [searchArray addObject:annotation];
            }
        }
        [self.mapView removeAnnotations:self.mapView.annotations];
        [self.mapView addAnnotations: searchArray];
    }
}

//搜地点按钮点击
- (void)searchButtonDidSelected:(UIButton *)serchButton{
    SearchViewController *searchVC = [[SearchViewController alloc]init];
    searchVC.location = _locService.userLocation.location.coordinate;
    //跳转到搜索视图
    [self.navigationController pushViewController:searchVC animated:YES];
}

#pragma mark -- 右上角更多选项视图
- (void)addRightMoreView{
    __weak __typeof (self)weakSelf = self;
    _moreView = [[RightMoreView alloc]initWithFrame:CGRectMake(0, 0, 200, 0)];
    [self.view addSubview:_moreView];
    //切换全部和故障站点block
    self.moreView.allOrBadStationBlcok = ^(NSString *string){
        if ([string  isEqualToString:@"全部"]) {
            NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
            [array addObjectsFromArray:weakSelf.badAnnotationArray];
            [array addObjectsFromArray:weakSelf.urgentAnnotationArray];
            [array addObjectsFromArray:weakSelf.yunweiAnnotationArray];
            [weakSelf.mapView removeAnnotations:array];
            [weakSelf.mapView addAnnotations:weakSelf.annotationArray];
        }else if ([string isEqualToString:@"故障"]){
            NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
            [array addObjectsFromArray:weakSelf.badAnnotationArray];
             [array addObjectsFromArray:weakSelf.urgentAnnotationArray];
             [array addObjectsFromArray:weakSelf.yunweiAnnotationArray];
            [weakSelf.mapView removeAnnotations:weakSelf.annotationArray];
            [weakSelf.mapView addAnnotations:array];
        }
    };
    //更新本地台站信息block
    self.moreView.updataStationBlock = ^(){
        weakSelf.jiangyuButton.selected = NO;
        weakSelf.wenduButton.selected = NO;
        [weakSelf.mapView removeAnnotations:weakSelf.mapView.annotations];
        weakSelf.statusArray = [NSMutableArray arrayWithCapacity:0];
        [[DataHandel sharedDataHandel] getStationStatusWithBlock:^(id object) {
            _statusArray = object;
            [weakSelf addAnnotation];
            
        }];
    };
    
    self.moreView.searchNearByBlock = ^(){
        
        SearchViewController *searchVC = [[SearchViewController alloc]init];
        searchVC.location = weakSelf.locService.userLocation.location.coordinate;
        //跳转到搜索视图
        [weakSelf.navigationController pushViewController:searchVC animated:YES];
    };
    [_moreView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(-40*8*hl);
        make.right.equalTo(self.view);
        make.width.mas_equalTo(0*wl);
        make.height.mas_equalTo(0);
    }];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"more"] style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemDidSelected:)];
    
}
#pragma mark -- 添加台站点
- (void) addAnnotation{
    //获取站点信息
    _stationArray = [NSMutableArray arrayWithCapacity:0];
    _annotationArray = [NSMutableArray array];
    //故障站点数组初始化
    _badStationArray = [NSMutableArray array];
    _urgencyStationArray = [NSMutableArray array];
    _operationStationArray = [NSMutableArray array];
    //故障标注点数组
    _badAnnotationArray = [NSMutableArray array];
     _urgentAnnotationArray = [NSMutableArray array];
     _yunweiAnnotationArray = [NSMutableArray array];
    [[DataHandel sharedDataHandel]getAllStationInfoListWIthBlock:^(id object) {
        
        NSString *location = [USER_DEFAULT objectForKey:@"UserLocation"];
//        NSLog(@"location:%@",location);
        NSArray *originArray = [NSArray arrayWithArray:(NSArray *)object];
        if ([location isEqualToString:@"石家庄"]) {
            
            _stationArray = [NSMutableArray arrayWithArray:originArray];
        }
        else{
            
            for (StationInfoModel *stationModel in originArray) {
                if ([stationModel.position containsString:location]) {
                    
                    [_stationArray addObject:stationModel];
                }
            }
        }
       
//        _stationArray = [NSArray arrayWithArray:(NSArray *)object];
        for (StationInfoModel *stationModel in _stationArray) {
//            HLog(@"%@",stationModel.stationStatus);
            STMPointAnnotation *annotation = [[STMPointAnnotation alloc]init];
            CLLocationCoordinate2D coor;
            coor.latitude = [stationModel.latitude floatValue];
            coor.longitude = [stationModel.longitude floatValue];
            annotation.coordinate = coor;
           
            
            
            if ([stationModel.stationStatus intValue] == 1) {
                //如果台站状态为1则不是故障站点，标注isBad1，显示绿色
                annotation.statusNum = 1;
            }else if ([stationModel.stationStatus intValue] == 0){
                //如果状态为0 则是故障站点，标注isBad属性为0，显示红色
                annotation.statusNum = 0;
//                //将故障站点model存入一个数组中
//                [_badStationArray addObject:stationModel];
//                //故障标注类存入数组
//                [_badAnnotationArray addObject:annotation];
            }else if ([stationModel.stationStatus integerValue] == 2){
                annotation.statusNum = 2;  //显示蓝色点
                //巡检任务
//                [_operationStationArray addObject:stationModel];
            }else if ([stationModel.stationStatus integerValue] == 3){
                //紧急任务
                annotation.statusNum = 3;
//                [_urgencyStationArray addObject:stationModel];
            }
            
            for (StatusModel *statusmodel in _statusArray) {
                
                if ([stationModel.stationNum isEqualToString:statusmodel.stationNum]) {
                    
                    if ([statusmodel.status intValue] == 1) {
                        //如果台站状态为1则不是故障站点，标注isBad1，显示绿色
                        annotation.statusNum = 1;
                    }else if ([statusmodel.status intValue] == 0){
                        //如果状态为0 则是故障站点，标注isBad属性为0，显示红色
                        annotation.statusNum = 0;
                      
                    }else if ([statusmodel.status intValue] == 2){
                        annotation.statusNum = 2;  //显示蓝色点
                        //巡检任务
//                        [_operationStationArray addObject:stationModel];
                    }else if ([statusmodel.status intValue] == 3){
                        //紧急任务
                        annotation.statusNum = 3;
//                        [_urgencyStationArray addObject:stationModel];
                    }

                }
            }
            
            if (annotation.statusNum == 0) {
                //将故障站点model存入一个数组中
                [_badStationArray addObject:stationModel];
                //故障标注类存入数组
                [_badAnnotationArray addObject:annotation];
            }
            else if (annotation.statusNum == 1){
                
            }
            else if (annotation.statusNum == 2){
                
                [_operationStationArray addObject:stationModel];
                [_yunweiAnnotationArray addObject:annotation];

            }
            else if (annotation.statusNum == 3){
                
                [_urgencyStationArray addObject:stationModel];
                [_urgentAnnotationArray addObject:annotation];

            }
            annotation.title = stationModel.stationName;
            //将model传给标注，供点击显示信息用
            annotation.stationModel = stationModel;
            [_annotationArray addObject:annotation];
        }
        //更改故障站点数量赋值
        [_rightTopButton setAttributedStringWithFaultString:[NSString stringWithFormat:@"故障(红)：%lu个",(unsigned long)_badStationArray.count] NormalString:@"" MaintainString:[NSString stringWithFormat:@"运维(蓝)：%lu个",(unsigned long)_operationStationArray.count] UrgntlyString:[NSString stringWithFormat:@"紧急(闪)：%lu个",(unsigned long)_urgencyStationArray.count]];
//        [_rightTopButton setAttributedStringWithFaultString:[NSString stringWithFormat:@"故障(红)：%lu个",(unsigned long)_badStationArray.count] MaintainString:[NSString stringWithFormat:@"运维(蓝)：%lu个",(unsigned long)_operationStationArray.count] UrgntlyString:[NSString stringWithFormat:@"紧急(闪)：%lu个",(unsigned long)_urgencyStationArray.count]];
//        long sum = _stationArray.count ;
//        long bad = _badStationArray.count;
//        [_rightTopButton setAttributedStringWithFaultString:[NSString stringWithFormat:@" 故障(红)：%lu个",(unsigned long)_badStationArray.count] NormalString:[NSString stringWithFormat:@" 正常(绿)：%lu个",(sum - bad)] MaintainString:nil UrgntlyString:nil];
        [_mapView addAnnotations:_annotationArray];
    }];
}

//添加底部视图
- (void)addBottomView{
    _bottomView = [[BottomView alloc]init];
    [self.view addSubview:_bottomView];
    _bottomView.backgroundColor = [UIColor whiteColor];
    //设置圆角
    _bottomView.layer.masksToBounds = YES;
    _bottomView.layer.cornerRadius = 8;
    __weak typeof(self)weakSelf = self;
    
    
    
    _bottomView.pushToWeihuBlock = ^(StationInfoModel *stationInfoModel){
       MaintainViewController *mainVC =  [[MaintainViewController alloc] init];
        
        for (StatusModel *statusmodel in weakSelf.statusArray) {
            
            if ([stationInfoModel.stationNum isEqualToString:statusmodel.stationNum]) {
                
                if ([statusmodel.status intValue] == 1) {
                    //如果台站状态为1则不是故障站点，标注isBad1，显示绿色
                    stationInfoModel.stationStatus = @"1";
                }else if ([statusmodel.status intValue] == 0){
                    //如果状态为0 则是故障站点，标注isBad属性为0，显示红色
                    stationInfoModel.stationStatus = @"0";
                    
                }else if ([statusmodel.status intValue] == 2){
                    stationInfoModel.stationStatus = @"2";
                    //巡检任务
                    //                        [_operationStationArray addObject:stationModel];
                }else if ([statusmodel.status intValue] == 3){
                   stationInfoModel.stationStatus = @"3";
                    //                        [_urgencyStationArray addObject:stationModel];
                }
                
            }

            
        }
        mainVC.stationModel = stationInfoModel;

        mainVC.currentTime = weakSelf.currentTime;
        mainVC.currentLocation = weakSelf.currentLocation;
        [weakSelf.navigationController pushViewController:mainVC animated:YES];
    };
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(8*wl);
        make.top.equalTo(self.view.mas_bottom).offset(2);
        make.right.equalTo(self.view.mas_right).offset(-8*wl);
        make.height.mas_equalTo(170*hl);
    }];
}

#pragma mark -- 添加右上方按钮，显示故障台站数量
- (void)addRightTopButton{
    _rightTopButton = [[RightTopButton alloc]init];
    [self.view addSubview:_rightTopButton];
    [_rightTopButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self);
        make.top.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(100, 90));
    }];
    [_rightTopButton.faultLabel setText:@"故障(红)："];
//    [_rightTopButton.normalLabel setText:@"  正常(绿)："];
    [_rightTopButton.maintainLabel setText:@"运维(蓝)："];
    [_rightTopButton.urgentlyLabel setText:@"紧急(闪)："];
    [_rightTopButton addTarget:self action:@selector(rightBtnDidSelected:) forControlEvents:UIControlEventTouchUpInside];
}
//点击右上方button
- (void)rightBtnDidSelected:(UIButton *)sender{
    //将故障站点数组传入
    DetailViewController * detail = [[DetailViewController alloc]init];
    detail.damageArray = _badStationArray;
    detail.urgencyArray = _urgencyStationArray;
    detail.operationArray = _operationStationArray;
    detail.userLatitude = _userLatitude;
    detail.userLongitude = _userLongitude;
    [self.navigationController pushViewController:detail animated:YES];
}

//定位
- (void)locationOnMap{
    //初始化BMKLocationService
    _locService = [[BMKLocationService alloc]init];
    _locService.delegate = self;
    
    _geocodesearch = [[BMKGeoCodeSearch alloc] init];
    
    _geocodesearch.delegate = self;
    //启动LocationService
    // _locService.userLocation
    [_locService startUserLocationService];
    //以下_mapView为BMKMapView对象
    _mapView.showsUserLocation = YES;//显示定位图层
    _mapView.userTrackingMode = BMKUserTrackingModeFollow;
}

#pragma mark -- 添加功能按钮的方法
- (void)addFunctionalButtons{
    UIButton *lukuangButton = [[UIButton alloc]init];       //开启关闭路况按钮
    _jiangyuButton = [[UIButton alloc]init];         //降雨button
    _wenduButton = [[UIButton alloc]init];           //温度button
    UIButton *weixingButton = [[UIButton alloc]init];           //开关卫星视图的按钮
    UIButton *qiehuanButton = [[UIButton alloc]init];          //切换地图2、3D按钮
    UIButton *xinxiButton = [[UIButton alloc]init];                //设置用户信息
    UIButton *renwuButton = [[UIButton alloc]init];             //下达任务按钮
//    UIButton *changeCenterButton = [[UIButton alloc]init];    //中心调整
    UIButton *yonghuButton = [[UIButton alloc]init];            //用户信息按钮
    //约束图片 添加点击方法
    [self setButtonConstraint:lukuangButton WithCount:0];
    [self setButtonConstraint:_jiangyuButton WithCount:1];
    [self setButtonConstraint:_wenduButton WithCount:2];
    [self setButtonConstraint:weixingButton WithCount:3];
    [self setButtonConstraint:qiehuanButton WithCount:4];
    [self setButtonConstraint:xinxiButton WithCount:5];
    
    NSString *job = [USER_DEFAULT objectForKey:@"Job"];
    NSString *power = [USER_DEFAULT objectForKey:@"czyPower"];
    if ([job isEqualToString:@"管理员"]) {
        
         [self setButtonConstraint:renwuButton WithCount:6];
    }
    else{
        
        if ([power containsString:@"10"]) {
            [self setButtonConstraint:renwuButton WithCount:6];
        }
        
    }
    
//    [self setButtonConstraint:renwuButton WithCount:6];
//    [self setButtonConstraint:changeCenterButton WithCount:6];
    [self setButtonConstraint:yonghuButton WithCount:7];
    UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(jiangyuButtonLongPress:)];
    longPressGR.minimumPressDuration = 0.8;
    [_jiangyuButton addGestureRecognizer:longPressGR];
}

//为按钮添加图片与约束点击方法等
- (void)setButtonConstraint:(UIButton *)button WithCount:(int)count{
    [self.view addSubview:button];
    ///将点击方法放进数组中
    NSArray *SELArray = @[
                          NSStringFromSelector(@selector(lukuangButtonDidSelected:)),
                          NSStringFromSelector(@selector(jiangyuButtonDidSelected:)),
                          NSStringFromSelector(@selector(wenduButtonDidSelected:)),
                          NSStringFromSelector(@selector(weixingBtnDidSelect:)),
                          NSStringFromSelector(@selector(qiehuangButtonDidSelecte:)),
                          NSStringFromSelector(@selector(xinxiButtonDidSelected:)),
                          NSStringFromSelector(@selector(renwuButtonDidSelected:)),
                          NSStringFromSelector(@selector(yonghuButtonDidSelected:))
                          ];
    //添加点击方法
    [button addTarget:self action:NSSelectorFromString(SELArray[count]) forControlEvents:UIControlEventTouchUpInside];
    //添加图片
    NSArray *imgArray = @[@"lukuang",@"jiangshui",@"wendu",@"weixing",@"dingwei",@"weihu_r",@"add_task_gray",@"mine"];
    NSArray *selectedImgAry = @[@"lukuang_high",@"jiangshui_high",@"wendu_high",@"weixing_high",@"dingwei_high",@"weihu_high",@"add_task_blue",@"mine_high"];
    [button setBackgroundImage:[UIImage imageNamed:imgArray[count]] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:selectedImgAry[count]] forState:UIControlStateSelected];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20*wl);
        make.top.equalTo(self.view).offset(100*hl + count * 75*hl);
        make.size.mas_equalTo(CGSizeMake(45*wl, 45*hl));
    }];
    if (count > 3) {
        count = count - 4;
        NSString *job = [USER_DEFAULT objectForKey:@"Job"];
        NSString *power = [USER_DEFAULT objectForKey:@"czyPower"];
        if (count == 3) {
            
            if ([job isEqualToString:@"管理员"]) {
                
                count = 3;
            }
            else{
                
                if ([power containsString:@"10"]) {
                    count = 3;
                }
                else{
                    count = 2;
                }
                
            }
        }
        
        
        [button mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view).offset(-20*hl);
            make.top.equalTo(self.view).offset(100*hl + count * 75*hl);
            make.size.mas_equalTo(CGSizeMake(45*wl, 45*hl));
        }];
    }
}

#pragma mark  -- mapView代理方法
// 重新定义标注视图
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    ///STMPointAnnotation 继承于BMKAnnotation 添加一个是否有故障的标记isBad
    STMPointAnnotation *STMannotation = (STMPointAnnotation *)annotation;
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        STMPinAnnotationView *newAnnotationView = [[STMPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
        newAnnotationView.animatesDrop = NO;// 设置该标注点动画显示
     
        
        if (STMannotation.statusNum == 1) {
            newAnnotationView.image = [self createGreenView];   //把大头针换成别的图片
        }else if (STMannotation.statusNum == 0){
            newAnnotationView.image = [self createRedView];
            
        }else if (STMannotation.statusNum == 2){
            newAnnotationView.image = [self createBlueView];
        }else if (STMannotation.statusNum == 3){
            
            newAnnotationView.image = [self createPinkView];
            newAnnotationView.imageView.backgroundColor = [UIColor clearColor];
            newAnnotationView.imageView.animationImages = @[[self createPinkView],[self createRedView]];
          

            newAnnotationView.imageView.animationDuration = 0.5;
            [newAnnotationView.imageView startAnimating];
            
            
            /*
            newAnnotationView.image = [UIImage imageNamed:@"round_fen"];
            //添加进数组中
            [_urgentAnnotationViewArray addObject:newAnnotationView];
            if (!_timer) {
                _timer = [NSTimer timerWithTimeInterval:0.3 target:self selector:@selector(chengImageForNewAnnotationView) userInfo:nil repeats:YES];
                [[NSRunLoop currentRunLoop]addTimer:_timer forMode:NSDefaultRunLoopMode];
            }
            if (!_timer1) {
                _timer1 = [NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(chengrfenForNewAnnotationView) userInfo:nil repeats:YES];
                [[NSRunLoop currentRunLoop]addTimer:_timer1 forMode:NSDefaultRunLoopMode];
            }
            */
        }
        
        if ([STMannotation.stationModel.stationType isEqualToString:@"T1"]) {
            
            newAnnotationView.typeLabel.text = @"B";
        }
        else if ([STMannotation.stationModel.stationType isEqualToString:@"T2"]){
            newAnnotationView.typeLabel.text = @"D";
        }
        else if ([STMannotation.stationModel.stationType isEqualToString:@"T4"]){
            newAnnotationView.typeLabel.text = @"T";
        }
        else if ([STMannotation.stationModel.stationType isEqualToString:@"T6"]){
            newAnnotationView.typeLabel.text = @"A";
        }
        else if ([STMannotation.stationModel.stationType isEqualToString:@"G2"]){
            newAnnotationView.typeLabel.text = @"G";
        }
        //站点标注赋值
        [newAnnotationView.nameLbel setText:STMannotation.title];
        [newAnnotationView.contentLabel setText:STMannotation.stationModel.temperatureOrRain];
        //将标注中的model传给标注视图作为属性
        newAnnotationView.stationModel = STMannotation.stationModel;
        return newAnnotationView;
    }
    return nil;
}

-(UIImage *)createGreenView{
    
    
    
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    greenView.backgroundColor = [UIColor greenColor];
    greenView.layer.masksToBounds = YES;
    greenView.layer.borderWidth = 2;
    greenView.layer.borderColor = [UIColor blackColor].CGColor;
    
    UIGraphicsBeginImageContext(greenView.bounds.size);
    [greenView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

-(UIImage *)createRedView{
    
    
    
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    greenView.backgroundColor = [UIColor redColor];
    greenView.layer.masksToBounds = YES;
    greenView.layer.borderWidth = 2;
    greenView.layer.borderColor = [UIColor blackColor].CGColor;
    
    UIGraphicsBeginImageContext(greenView.bounds.size);
    [greenView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}


-(UIImage *)createBlueView{
    
    
    
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    greenView.backgroundColor = [UIColor blueColor];
    greenView.layer.masksToBounds = YES;
    greenView.layer.borderWidth = 2;
    greenView.layer.borderColor = [UIColor blackColor].CGColor;
    
    UIGraphicsBeginImageContext(greenView.bounds.size);
    [greenView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}


-(UIImage *)createPinkView{
    
    
    
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    greenView.backgroundColor = [UIColor colorWithRed:255/255.0 green:181/255.0 blue:177/255.0 alpha:1.0];
    greenView.layer.masksToBounds = YES;
    greenView.layer.borderWidth = 2;
    greenView.layer.borderColor = [UIColor blackColor].CGColor;
    
    UIGraphicsBeginImageContext(greenView.bounds.size);
    [greenView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
/*
- (void)chengImageForNewAnnotationView{
    for (STMPinAnnotationView *annView in _urgentAnnotationViewArray) {
        annView.image = [UIImage imageNamed:@"round_hong"];
    }
 }
- (void)chengrfenForNewAnnotationView{
    for (STMPinAnnotationView *annView in _urgentAnnotationViewArray) {
        annView.image = [UIImage imageNamed:@"round_fen"];
    }
}
*/
//点击大头针的代理方法
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{
    STMPinAnnotationView *STMView = (STMPinAnnotationView *)view;
    NSLog(@"%@,%@",STMView.stationModel.stationName,STMView.stationModel.stationStatus);
    //将当前位置传给底部视图的location属性，供导航时作为起点坐标
    _bottomView.location =  _locService.userLocation.location;
    _bottomView.model = STMView.stationModel;
    //弹出底部视图并通过model为视图赋值
    [_bottomView setDataOnTheseLabelWithStationModel:STMView.stationModel];
    [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).offset(-8*hl);
        make.left.equalTo(self.view).offset(8*wl);
        make.right.equalTo(self.view.mas_right).offset(-8*wl);
        make.height.mas_equalTo(190*hl);
    }];
}

//取消点击大头针（台站站点）的方法
- (void)mapView:(BMKMapView *)mapView didDeselectAnnotationView:(BMKAnnotationView *)view{
    [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(8*wl);
        make.top.equalTo(self.view.mas_bottom);
        make.right.equalTo(self.view.mas_right).offset(-8*wl);
        make.height.mas_equalTo(180*hl);
    }];
}
#pragma mark -- 定位代理方法
/**
 *在将要启动定位时，会调用此函数
 */
- (void)willStartLocatingUser{
    
}

/**
 *在停止定位后，会调用此函数
 */
- (void)didStopLocatingUser{
    
}

//实现相关delegate 处理位置信息更新
//处理方向变更信息
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
//    NSLog(@"heading is %@",userLocation.heading);
    [_mapView updateLocationData:userLocation];
}

//处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
//    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    _userLatitude = userLocation.location.coordinate.latitude;
    _userLongitude = userLocation.location.coordinate.longitude;
    [_mapView updateLocationData:userLocation];
    
    //地理反编码
    
    BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
    
    reverseGeocodeSearchOption.reverseGeoPoint = userLocation.location.coordinate;
    
    BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
    
    if(flag){
        
        NSLog(@"反geo检索发送成功");
        
        [_locService stopUserLocationService];
        
    }else{
        
        NSLog(@"反geo检索发送失败");
        
    }
    
}

-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error

{
    
    NSLog(@"address:%@",result.address);
    
    _currentLocation = result.address;

}




#pragma mark -- 功能按钮点击方法
//切换路况按钮点击
- (void)lukuangButtonDidSelected:(UIButton *)sender{
    
    
    
    if (sender.selected == NO) {
        //进入选中状态
        sender.selected = YES;
        //打开实时路况图层
        [_mapView setTrafficEnabled:YES];
    }else{
        //取消选中状态
        sender.selected = NO;
        //关闭实时路况图层
        [_mapView setTrafficEnabled:NO];
    }
}
//降雨按钮点击
- (void)jiangyuButtonDidSelected:(UIButton *)sender{
    if (sender.selected == NO) {
        //进入选中状态
        sender.selected = YES;
        [self addRainDataOnAnnotationViewWithHour:24];
    }else{
        sender.selected = NO;
        for (StationInfoModel *stationModel in _stationArray) {
            stationModel.temperatureOrRain = @"";
        }
        [self exchangeAnnotation];
    }
    
}

//降雨按钮长按
- (void)jiangyuButtonLongPress:(UILongPressGestureRecognizer *)longPressGR{
    UIButton *jiangshuiBtn = (UIButton *) longPressGR.view;
    if (longPressGR.state == UIGestureRecognizerStateBegan) {
       //[jiangshuiBtn setBackgroundImage:[UIImage imageNamed:@"jiangshui_one"] forState:UIControlStateNormal];
        [self addRainDataOnAnnotationViewWithHour:1];
        
        
        
    }
}
//温度按钮点击
- (void)wenduButtonDidSelected:(UIButton *)sender{
    if (sender.selected == NO) {
        //进入选中状态
        sender.selected = YES;
        [[DataHandel sharedDataHandel]getTemperatureDataWithBlock:^(id object) {
            NSArray *temArray = (NSArray *)object;
            //具有温度数据的数组 ,将具有温度数据的站点数据添加到临时数组中，然后从所有站点数组中将其删除留下的是只有降水数据的站点，点击温度时将只有降水数据的站点的数据label设置为不显示数据
            NSMutableArray *temperatureTempAry = [NSMutableArray array];
            for (StationInfoModel *stModel in _stationArray) {
                for (NSDictionary *temDict in temArray) {
                    if ([stModel.stationNum isEqualToString:[temDict objectForKey:@"站号"]]) {
                        stModel.temperatureOrRain = [NSString stringWithFormat:@"%@",[temDict objectForKey:@"气温"]];
                        [temperatureTempAry addObject:stModel];
                    }
                }
            }
            //取出只有降水数据的站点，将它们显示数据的label置空
            NSArray *onlyRainArray = [_stationArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"NOT (SELF in %@)",temperatureTempAry ]];
            for (StationInfoModel *staModel in onlyRainArray) {
                staModel.temperatureOrRain = @" ";
            }
            ///刷新百度地图标注
            [self exchangeAnnotation];
        }];
        
        //改变降水button的状态
        _jiangyuButton.selected = NO;
    }else{
        sender.selected = NO;
        for (StationInfoModel *stationModel in _stationArray) {
            stationModel.temperatureOrRain = @"";
        }
        [self exchangeAnnotation];
    }
}
//切换卫星地图按钮点击方法
- (void)weixingBtnDidSelect:(UIButton *)sender{
    
    if (sender.selected == NO) {
        sender.selected = YES;
        //切换为卫星图
        [_mapView setMapType:BMKMapTypeSatellite];
    }else{
        sender.selected = NO;
        //切换为普通地图
        [_mapView setMapType:BMKMapTypeStandard];
    }
}
//切换2、3D地图按钮点击方法
- (void)qiehuangButtonDidSelecte:(UIButton *)sender{
    if (sender.selected == NO) {
        sender.selected = YES;
    }else{
        sender.selected = NO;
    }
    _mapView.userTrackingMode = BMKUserTrackingModeFollowWithHeading;
}
//信息设置按钮点击
- (void)xinxiButtonDidSelected:(UIButton *)sender{
    [self addBackViewOnWindow];
    UserInfoAlertView *userAlert = [[UserInfoAlertView alloc]init];
    if ([USER_DEFAULT objectForKey:@"weihurenyuan"]) {
        [userAlert.userTextField setText:[NSString stringWithFormat:@"  %@",[USER_DEFAULT objectForKey:@"weihurenyuan"]]];
    }else{
        UserInfoModel *userInfoModel = [NSKeyedUnarchiver unarchiveObjectWithData:[USER_DEFAULT objectForKey:@"userInfoModel"]];
        [userAlert.userTextField setText:[NSString stringWithFormat:@"  %@",userInfoModel.RealName]];
    }
    [self.view.window addSubview:userAlert];
    userAlert.tag = 170313;
    [userAlert mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view.window);
        make.size.mas_equalTo(CGSizeMake(300*wl, 150*hl));
    }];
}
//下达任务按钮点击 改为中心调整
- (void)renwuButtonDidSelected:(UIButton *)sender{
    TaskViewController * task = [[TaskViewController alloc]init];
    [self.navigationController pushViewController:task animated:YES];
//    [_mapView setCenterCoordinate:_locService.userLocation.location.coordinate animated:YES];
}
//用户信息按钮点击
- (void)yonghuButtonDidSelected:(UIButton *)sender{
    [self addBackViewOnWindow];
    MeInfoView *meInfoView = [[MeInfoView alloc]init];
    meInfoView.tag = 170316;
    UserInfoModel *userModel = [NSKeyedUnarchiver unarchiveObjectWithData:[USER_DEFAULT objectForKey:@"userInfoModel"]];
    [meInfoView setTextForLabelsByUserName:[USER_DEFAULT objectForKey:@"userName"] UserId:userModel.UserID Name:userModel.RealName Type:userModel.UserType];
    [self.view.window addSubview:meInfoView];
    [meInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view.window);
        make.size.mas_equalTo(CGSizeMake([UIScreen mainScreen].bounds.size.width *3/4, 200*hl));
    }];
}

- (void)addBackViewOnWindow{
    UIView *backView = [[UIView alloc]init];
    backView.backgroundColor = RGBACOLOR(0, 0, 0, 0.5);
    [self.view.window addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.view.window);
    }];
    UITapGestureRecognizer *tapGAR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backVIewTapGRAction:)];
    [backView addGestureRecognizer:tapGAR];
    backView.tag = 170311;
}

//半透明视图手势方法
- (void)backVIewTapGRAction:(UITapGestureRecognizer *)tapGR{
    UIView *backView = [self.view.window viewWithTag:170311];
    [backView removeFromSuperview];
    UserInfoAlertView *userView = [self.view.window viewWithTag:170313];
    [userView removeFromSuperview];
    MeInfoView *meInfoView = [self.view.window viewWithTag:170316];
    if (meInfoView) {
        [meInfoView removeFromSuperview];
    }
}

//根据参数显示不同时间段数据 （降水按钮点击显示24小时，长按显示1小时）
- (void)addRainDataOnAnnotationViewWithHour:(int)hour{
    //改变温度按钮的状态
    _wenduButton.selected = NO;
    [[DataHandel sharedDataHandel]getRainDataWithHour:hour Block:^(id object) {
        NSArray *rainAry = (NSArray *)object;
        for (NSDictionary *rainDict in rainAry) {
            for (StationInfoModel *stationModel in _stationArray) {
                if ([stationModel.stationNum isEqualToString:[rainDict objectForKey:@"站号"]]) {
                    stationModel.temperatureOrRain = [NSString stringWithFormat:@"%@",[rainDict objectForKey:@"降水"]];
                }
            }
        }
        //切换标注
        [self exchangeAnnotation];
    }];
}

#pragma mark -- 切换标注方法（点击降水、温度按钮和更多选项中显示故障或全部切换使用）
- (void)exchangeAnnotation{
    if ([_mapView.annotations isEqualToArray:_annotationArray]) {
        //移除原来的所有点
        [_mapView removeAnnotations:_annotationArray];
        [_mapView addAnnotations:_annotationArray];
    }else if ([_mapView.annotations isEqualToArray:_badAnnotationArray]){
        [_mapView removeAnnotations:_badAnnotationArray];
        [_mapView addAnnotations:_badAnnotationArray];
    }
}

#pragma mark -- 点击导航栏右边按钮
- (void)rightBarButtonItemDidSelected:(UIBarButtonItem *)barButton{
    if (_moreView.frame.size.height == 0) {
        [UIView animateWithDuration:2.0 animations:^{
            [_moreView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.view);
                make.right.equalTo(self.view);
                make.width.mas_equalTo(170*wl);
                make.height.mas_equalTo(40*_moreView.dataArray.count*hl);
            }];
        }];
    }else{
        //收回
        [self takeBackMoreView];
    }
}

#pragma mark -- 收回又上角列表视图
- (void)takeBackMoreView{
    [UIView animateWithDuration:2.0 animations:^{
        [_moreView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).offset(-40*8*hl);
            make.right.equalTo(self.view);
            make.width.mas_equalTo(0*wl);
            make.height.mas_equalTo(0);
        }];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
